package liuch.priority;
/**
 * @author 17101651
 * @ClassName PriorityRunSpeed
 * @Description 优先级高的线程会获得CPU执行机会多
 * @data 2018年09月06日
 */
public class PriorityRunSpeed {
    public static void main(String[] args) {
        try {
            MyThreadA myThreadA = new MyThreadA();
            myThreadA.setPriority(Thread.NORM_PRIORITY + 4);
            myThreadA.start();

            MyThreadB myThreadB = new MyThreadB();
            myThreadB.setPriority(Thread.NORM_PRIORITY - 4);
            myThreadB.start();

            Thread.sleep(2000);
            myThreadA.stop();
            myThreadB.stop();
            System.out.println(myThreadA.getCount());
            System.out.println(myThreadB.getCount());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class MyThreadA extends Thread {
    int count = 0;

    public int getCount() {
        return count;
    }

    @Override
    public void run() {
        while (true) {
            count++;
        }
    }
}

class MyThreadB extends Thread {
    int count = 0;

    public int getCount() {
        return count;
    }

    @Override
    public void run() {
        while (true) {
            count++;
        }
    }
}
